/**
 * Created by Administrator on 2014/12/11.
 */

function LogItem(source) {
    this.source = source;
    this.key = getStrbyPattern(this.KEY_PATTERN, this.source);
    this.message = getStrbyPattern(this.MSG_PATTEN, this.source);
    this.count = 1;
}

LogItem.prototype.compare = function (another) {
    //类型不同，返回false
    if (!another instanceof LogItem) {
        return false;
    }
    //相同引用，返回true
    if (another === this) {
        return true;
    }
    return this.key === another.key && this.message === another.message;
};

LogItem.prototype.toString = function () {
    var header = 'Exception happen count:(' + this.count + ')\r\n';
    return header + this.source + '\r\n';
};

LogItem.prototype.KEY_PATTERN = /"Url" : "((?:\w*:\/\/[^\/\?"]*)?(?:\/[^\/\?"]*){1,2})/;
LogItem.prototype.MSG_PATTEN = /"Message" : "([^"]*)"/;

function getStrbyPattern(pattern, source) {
    var match = pattern.exec(source);
    return (match && match.pop()) || "";
}

module.exports = LogItem;